function [ ] = main()

% Cleanup
delete 'Source/dataForTrg.mat';
delete 'Target/dataForTrg.mat';

dbstop if error

dir='Models/Cat/';
srcFile = 'cat0.obj';
trgFiles = 'cat2.obj';
%trgFiles = 'cat4.obj';
%trgFiles = 'cat7.obj';
vertexSampling = 1179;

%dir='Models/Centaur/';
%srcFile = 'centaur01.obj';
%trgFiles = 'centaur02.obj';
%trgFiles = 'centaur03.obj';
%trgFiles = 'centaur06.obj';
%vertexSampling = 5439;


%{
dir = 'Models/Embossed/';
srcFile = 'embossed01.obj';
trgFiles = 'embossed02.obj';
vertexSampling = 1;
%}

% = = = = = = = = = = = = = = = = = = = =

dataFile1 = [dir srcFile '.allData.mat'];
dataFile2 = [dir trgFiles '.allData.mat'];

load(dataFile1);
% Load the source mesh
srcVertices = vertices;
srcTriangles = triangles;

load(dataFile2);



minL = -ones(size(srcVertices,1),1);
step = 1000;

% kk
%vertexSampling = [1:size(srcVertices,1)]';

% Lady
% vertexSampling = 735;
% Cat
%vertexSampling = 1179;
% Centaur
%vertexSampling = 5439;

for i = 1 : size(vertexSampling, 1)
    
    vID = vertexSampling(i);
    %vID=vertexSampling(i:min(i+step-1,numel(vertexSampling)));
    %vID=[4051,4052,4039];
    
    % Compute on the source mesh
    cd 'Source';
    main(strcat('../',dir,srcFile,'.allData.mat'),vID);
    copyfile 'dataForTrg.mat' '../Target';
    cd '../Target';
    
    % Compute on the target mesh
    [trgTri, trgTriW, cost] = main( ['../' dir trgFiles '.allData.mat'],'dataForTrg.mat' );
    cd '..';
    
    % Compute the quality of matching of the source mesh
    assert(numel(vID)==numel(trgTri));
    for j=1:numel(trgTri)
        resultPos=srcVertices(srcTriangles(trgTri(j),:),:)'*trgTriW(j,:)';
        resultPos=resultPos';
        srcPos=srcVertices(vID(j),:);
        minL(vID(j))=norm([-resultPos(1),resultPos(2),resultPos(3)]-srcPos);
        if minL(vID(j))>norm(resultPos-srcPos)
            minL(vID(j))=norm(resultPos-srcPos);
        end
    end
    disp(['Processing v:',num2str(vID(1)),', error:',num2str(minL(vID(j)))]);
    
    % Save minL
    %save([dir trgFiles(obj, :) '.minL.txt'], 'minL', '-ascii');
    
end % for vertexSampling


end % main

